package 数组.easy;

/**
 * @author Lw中
 * @date 2020/9/15 14:21
 */
public class ErLu {

    /**
     * 26.删除排序数组中的重复项
     * 使用双指针，循环体中i是快指针，自定义变量low是慢指针
     * @param nums
     * @return
     */
    public static int removeDuplicates(int[] nums) {
        if (nums.length == 0) {
            return 0;
        }
        int low = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[low] != nums[i]) {
                low++;
                nums[low] = nums[i];
            }
        }
        return low + 1;
    }

    public static void main(String[] args) {
        int[] arr = {0,0,1,1,1};
        int i = removeDuplicates(arr);
        System.out.println(i);
    }

}
